package com.baizhi.service.impl;

import com.baizhi.entity.Record;
import com.baizhi.mapper.RecordMapper;
import com.baizhi.service.IRecordService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author longyang
 * @since 2022-01-11
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements IRecordService {
    @Autowired
    private RecordMapper recordMapper;

    public PageInfo<Record> selectAllRecord(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Record> records = recordMapper.selectList(null);
        PageInfo<Record> bookPageInfo = new PageInfo<Record>(records);
        return bookPageInfo;
    }

    public Integer updateRecord(Record record) {
        return recordMapper.updateById(record);
    }

    public Integer deleteRecord(Integer rid) {
        return  recordMapper.deleteById(rid);
    }

    public Integer addRecord(Record record) {
        return recordMapper.insert(record);
    }
    public List<Record> selcetByRname(String Rname) {
        //条件构造器：用于构建sql条件
        QueryWrapper<Record> queryWrapper = new QueryWrapper<Record>();
        queryWrapper.like("name",Rname);
        List<Record> records = recordMapper.selectList(queryWrapper);
        return records;
    }
}
